package com.yx.cloud.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.yx.cloud.R;
import com.iot.base.bean.account.UserFeedBack;
import com.yx.cloud.utils.StringUtils;

import java.util.List;

public class FeedBackDetailsAdapter extends RecyclerView.Adapter {
    private final static String TAG = "FeedBackDetailsAdapter";
    private Context mContext;
    private List<UserFeedBack> mList;

    public FeedBackDetailsAdapter(Context context, List<UserFeedBack> list) {
        mContext = context;
        mList = list;
    }

    public enum ItemType {
        ITEM1, ITEM2
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ItemType.ITEM1.ordinal()) {
            View itemView = LayoutInflater.from(mContext).inflate(R.layout.put_question_feedbackdetails_item, parent, false);
            PutQuestionViewHolder PutQuestionHolder = new PutQuestionViewHolder(itemView);//提问
            return PutQuestionHolder;
        } else if (viewType == MainAddAdapter.ItemType.ITEM2.ordinal()) {
            View itemView = LayoutInflater.from(mContext).inflate(R.layout.reply_feedbackdetails_item, parent, false);
            ReplyViewHolder ReplyHolder = new ReplyViewHolder(itemView);//回答
            return ReplyHolder;
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        UserFeedBack bean = mList.get(position);
        if (holder instanceof PutQuestionViewHolder) {
            ((PutQuestionViewHolder) holder).mTvFeedbackDetailsContent.setText(bean.getContent());
            long ctime = bean.getTime();
            ((PutQuestionViewHolder) holder).mTvFeedbackDetailsTime.setText(StringUtils.timeStamp2Date(ctime, "yyyy-MM-dd HH:mm:ss"));
        } else if (holder instanceof ReplyViewHolder) {
            ((ReplyViewHolder) holder).mTvFeedbackDetailsContent.setText(bean.getContent());
            long ctime = bean.getTime();
            ((ReplyViewHolder) holder).mTvFeedbackDetailsTime.setText(StringUtils.timeStamp2Date(ctime, "yyyy-MM-dd HH:mm:ss"));
        }
        (holder).itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
//        Log.i(TAG, "查询反馈会话列表iiiiiiiiiiiiiiiiiiiiiiii : " + mList.size());
        return mList.size();
    }

    @Override
    public int getItemViewType(int position) {
        UserFeedBack bean = mList.get(position);
        if (bean.getOwner() == UserFeedBack.USER) {
            return ItemType.ITEM1.ordinal();
        } else {
            return ItemType.ITEM2.ordinal();
        }
    }

    class PutQuestionViewHolder extends RecyclerView.ViewHolder {
        TextView mTvFeedbackDetailsContent;
        TextView mTvFeedbackDetailsTime;

        public PutQuestionViewHolder(View itemView) {
            super(itemView);
            mTvFeedbackDetailsContent = itemView.findViewById(R.id.tv_detailsContent);
            mTvFeedbackDetailsTime = itemView.findViewById(R.id.tv_detailsTime);
        }
    }

    class ReplyViewHolder extends RecyclerView.ViewHolder {
        TextView mTvFeedbackDetailsContent;
        TextView mTvFeedbackDetailsTime;

        public ReplyViewHolder(View itemView) {
            super(itemView);
            mTvFeedbackDetailsContent = itemView.findViewById(R.id.tv_detailsContent);
            mTvFeedbackDetailsTime = itemView.findViewById(R.id.tv_detailsTime);
        }
    }
}
